#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "CheckerBoard.h"

using namespace std;

CheckerBoard::CheckerBoard()
{
	int i = 0;
	int j = 0;
	type1 = UNINITIALIZED;
	type2 = UNINITIALIZED;
	player1 = PLAYER;
	player2 = PLAYER;
	size = 10;
	Board = (Pawn***) malloc((size/2) * sizeof (Pawn**));
	for (i=0;i<size/2;i++){
		Board[i] = (Pawn**) malloc(size * sizeof (Pawn*));
	}
	turn = WHITE;
	createList(&LoEat);
	createList(&LoJump);
	createList(&LoDanger);
	selectedPawnX = 10;
	selectedPawnY = 10;
	jumpAIx = 10;
	jumpAIy = 10;
	for (j=0;j<size;j++)
	{
		if (j != (size/2)-1 && j != size/2)
		{
			for (i=0;i<(size/2);i++)
			{
				if (j < size/2)
				{
					Board[i][j] = new Pawn(WHITE);
				}
				else 
				{
					Board[i][j] = new Pawn(BLACK);
				}
			}
		}
		else 
		{
			for (i=0;i<size/2;i++)
			{
				Board[i][j] = NULL;
			}
		}
	}
}


CheckerBoard::CheckerBoard(int sizes)
{
	int i = 0;
	int j = 0;
	size = sizes;
	Board = (Pawn***) malloc((size/2) * sizeof (Pawn**));
	for (i=0;i<size/2;i++){
		Board[i] = (Pawn**) malloc(size * sizeof (Pawn*));
	}
	turn = WHITE;
	createList(&LoEat);
	createList(&LoJump);
	createList(&LoDanger);
	numberOfPawn1 = 12;
	numberOfPawn2 = 12;
	selectedPawnX = 10;
	selectedPawnY = 10;
	jumpAIx = 10;
	jumpAIy = 10;
	for (j=0;j<size;j++)
	{
		if (j != (size/2)-1 && j != size/2)
		{
			for (i=0;i<(size/2);i++)
			{
				if (j < size/2)
				{
					Board[i][j] = new Pawn(WHITE);
				}
				else 
				{
					Board[i][j] = new Pawn(BLACK);
				}
			}
		}
		else 
		{
			for (i=0;i<size/2;i++)
			{
				Board[i][j] = NULL;
			}
		}
	}
}

CheckerBoard::CheckerBoard(const CheckerBoard& cb){}

CheckerBoard::~CheckerBoard(){};

bool CheckerBoard::isExistPawn(int x, int y)
{
	if (x<0 || x>(size/2)-1 || y<0 || y>size-1){ return false;}
	return (Board[x][y] != NULL);
}

bool CheckerBoard::isExistWhitePawn(int x, int y)
{
	return (isExistPawn(x,y) && Board[x][y]->side==WHITE);
}

bool CheckerBoard::isExistBlackPawn(int x, int y)
{
	return (isExistPawn(x,y) && Board[x][y]->side==BLACK);
}

bool CheckerBoard::isExistWhiteKingPawn(int x, int y)
{
	return (isExistWhitePawn(x,y) && Board[x][y]->isKing);
}

bool CheckerBoard::isExistBlackKingPawn(int x, int y)
{
	return (isExistBlackPawn(x,y) && Board[x][y]->isKing);
}

bool CheckerBoard::isDanger(int x, int y)
{
	if (Board[x][y]->side==WHITE){
		if (y%2==0){
			if (y!=0 && y!=size-1 && x!=0){
				return((isExistBlackPawn(x-1,y+1) && !isExistPawn(x,y-1))||
					   (isExistBlackPawn(x,y+1)  && !isExistPawn(x-1,y-1))||			
					   (isExistBlackKingPawn(x-1,y-1)  && !isExistPawn(x,y+1))||
					   (isExistBlackKingPawn(x,y-1)  && !isExistPawn(x-1,y+1)));
			} else {return false;}
		}else{
			if (y!=0 && y!=size-1 && x!=(size/2)-1){
				return ((isExistBlackPawn(x,y+1) && !isExistPawn(x+1,y-1)) ||
						(isExistBlackPawn(x+1,y+1)  && !isExistPawn(x,y-1)) ||
						(isExistBlackKingPawn(x,y-1)  && !isExistPawn(x+1,y+1)) ||
						(isExistBlackKingPawn(x+1,y-1)  && !isExistPawn(x,y+1)));
			} else {return false;}
		}
	}else{
		if (y%2==0){
			if (y!=0 && y!=size-1 && x!=0){
				return ((isExistWhitePawn(x-1,y-1) && !isExistPawn(x,y+1)) ||
						(isExistWhitePawn(x,y-1)  && !isExistPawn(x-1,y+1)) ||
						(isExistWhiteKingPawn(x-1,y+1)  && !isExistPawn(x,y-1)) ||
						(isExistWhiteKingPawn(x,y+1)  && !isExistPawn(x-1,y+1)));
			}else {return false;}
		}else{
			if (y!=0 && y!=size-1 && x!=(size/2)-1){
				return ((isExistWhitePawn(x,y-1) && !isExistPawn(x+1,y+1)) ||
						(isExistWhitePawn(x+1,y-1)  && !isExistPawn(x,y+1)) ||
						(isExistWhiteKingPawn(x,y+1)  && !isExistPawn(x+1,y-1)) ||
						(isExistWhiteKingPawn(x+1,y+1)  && !isExistPawn(x,y+1)));
			} else {return false;}
		}
	}
}

bool CheckerBoard::isEatAllowed(int x, int y)
{
	bool eat = false;
	if (Board[x][y]->isKing == true)
	{
		if (x > 0 && y > 1)
		{
			eat = isJump(x,y,x-1,y-2,true);
			if (eat) 
			{
				return true;
			}
		}
		
		if (x > 0 && y < size-2)
		{
			eat = isJump(x,y,x-1,y+2,true);
			if (eat) 
			{
				return true;
			}
		}
				
		if (x < (size/2)-1 && y > 1)
		{
			eat = isJump(x,y,x+1,y-2,true);
			if (eat) 
			{
				return true;
			}		
		}
		
		if (x < (size/2)-1 && y < size-2)
		{
			eat = isJump(x,y,x+1,y+2,true);
			if (eat) 
			{
				return true;
			}		
		}
	}
	else if (Board[x][y]->side == BLACK)
	{
		if (x > 0 && y > 1)
		{
			eat = isJump(x,y,x-1,y-2,true);
			if (eat) 
			{
				return true;
			}
		}
		
		if (x < (size/2)-1 && y > 1)
		{
			eat = isJump(x,y,x+1,y-2,true);
			if (eat) 
			{
				return true;
			}		
		}
	}
	else if (Board[x][y]->side == WHITE)
	{			
		if (x > 0 && y < size-2)
		{
			eat = isJump(x,y,x-1,y+2,true);
			if (eat) 
			{
				return true;
			}
		}
			
		if (x < (size/2)-1 && y < size-2)
		{
			eat = isJump(x,y,x+1,y+2,true);
			if (eat) 
			{
				return true;
			}		
		}
	}
	return false;
}

bool CheckerBoard::isJump(int x1, int y1, int x2, int y2, bool check)
{
	if (isExistPawn(x2,y2) || x2 < 0 || x2 > (size/2)-1 || y2 < 0 || y2 > size)
	{
		return false;
	}
	
	if (y1%2==0)
	{
		if (x2==x1+1 && y2==y1+2 && isExistPawn(x1,y1+1) && Board[x1][y1+1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==WHITE)) 
		{
			if (!check)
			{
				free(&(Board[x1][y1+1]));
				Board[x1][y1+1]=NULL;
			}
			return true;
		}
		else if(x2==x1-1 && y2==y1+2 && isExistPawn(x1-1,y1+1) && Board[x1-1][y1+1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==WHITE))
		{
			if (!check)
			{
				free(&(Board[x1-1][y1+1]));
				Board[x1-1][y1+1]=NULL;
			}
			return true;
		}
		else if(x2==x1+1 && y2==y1-2 && isExistPawn(x1,y1-1) && Board[x1][y1-1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==BLACK))
		{
			if (!check)
			{
				free(&(Board[x1][y1+1]));
				Board[x1][y1-1]=NULL;
			}
			return true;
		}
		else if(x2==x1-1 && y2==y1-2 && isExistPawn(x1-1,y1-1) && Board[x1-1][y1-1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==BLACK))
		{
			if (!check)
			{
				free(&(Board[x1-1][y1-1]));
				Board[x1-1][y1-1]=NULL;
			}
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		if (x2==x1+1 && y2==y1+2 && isExistPawn(x1+1,y1+1) && Board[x1+1][y1+1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==WHITE)) 
		{
			if (!check)
			{
				free(&(Board[x1+1][y1+1]));
				Board[x1+1][y1+1]=NULL;
			}
			return true;
		}
		else if(x2==x1-1 && y2==y1+2 && isExistPawn(x1,y1+1) && Board[x1][y1+1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==WHITE))
		{
			if (!check)
			{
				free(&(Board[x1][y1+1]));
				Board[x1][y1+1]=NULL;
			}
			return true;
		}
		else if(x2==x1+1 && y2==y1-2 && isExistPawn(x1+1,y1-1) && Board[x1+1][y1-1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==BLACK))
		{
			if (!check)
			{
				free(&(Board[x1+1][y1+1]));
				Board[x1+1][y1-1]=NULL;
			}
			return true;
		}
		else if(x2==x1-1 && y2==y1-2 && isExistPawn(x1,y1-1) && Board[x1][y1-1]->side != Board[x1][y1]->side && (Board[x1][y1]->isKing || Board[x1][y1]->side==BLACK))
		{
			if (!check)
			{
				free(&(Board[x1][y1-1]));
				Board[x1][y1-1]=NULL;
			}
			return true;
		}
		else 
		{
			return false;
		}
	}
}

bool CheckerBoard::isMoveAllowed(int x1, int y1, int x2, int y2)
{
	if (isExistPawn(x2,y2) || x2 < 0 ||  x2 > (size/2)-1 || y2 < 0 || y2 > size-1)
	{
		return false;
	}
	else
	{
		if (isJump(x1,y1,x2,y2,false))	// Check Jump Allowed
		{
			return true;
		}
		else if (isEmpty(LoEat))
		{
			if (y1%2==0)
			{
				if (Board[x1][y1]->side == WHITE)
				{
					if ((x2==x1-1 && y2==y1+1) || (x2==x1 && y2==y1+1))
					{
						return true;
					}
					else if (Board[x1][y1]->isKing && ((x2==x1-1 && y2==y1-1) || (x2==x1 && y2==y1-1)))
					{
						return true;
					}
					else 
					{
						return false;
					}
				}
				else 
				{
					if ((x2==x1-1 && y2==y1-1) || (x2==x1 && y2==y1-1))
					{
						return true;
					}
					else if (Board[x1][y1]->isKing && ((x2==x1-1 && y2==y1+1) || (x2==x1 && y2==y1+1)))
					{
						return true;
					}
					else 
					{
						return false;
					}
				}
			}
			else 
			{
				if (Board[x1][y1]->side == WHITE)
				{
					if ((x2==x1+1 && y2==y1+1) || (x2==x1 && y2==y1+1))
					{
						return true;
					}
					else if (Board[x1][y1]->isKing && ((x2==x1+1 && y2==y1-1) || (x2==x1 && y2==y1-1)))
					{
						return true;
					}
					else 
					{
						return false;
					}
				}
				else 
				{
					if ((x2==x1+1 && y2==y1-1) || (x2==x1 && y2==y1-1))
					{
						return true;
					}
					else if (Board[x1][y1]->isKing && ((x2==x1+1 && y2==y1+1) || (x2==x1 && y2==y1+1)))
					{
						return true;
					}
					else 
					{
						return false;
					}
				}
			}
		}
		else 
		{
			return false;
		}
	}
}


void CheckerBoard::checkEat(bool turn)
{
	int i,j;
	for (j=0;j<size;j++)
	{
		for (i=0;i<size/2;i++)
		{
			if (Board[i][j] != NULL)
			{
				if (Board[i][j]->side == turn)
				{
					if (isEatAllowed(i,j)){add(&LoEat,i,j);}
				}
			}
		}
	}
}

void CheckerBoard::checkSafe(bool turn)
{
	int i,j;
	for(i=0;i<size/2;i++){
		for(j=0;j<size;j++){
			if(turn==WHITE && isExistWhitePawn(i,j)){
				if (isDanger(i,j)){add(&LoDanger,i,j);}
			}else if (turn==BLACK && isExistBlackPawn(i,j)){
				if (isDanger(i,j)){add(&LoDanger,i,j);}
			}
		}	
	}
}

bool CheckerBoard::isMoveable(int x, int y){
	int X1,X2;
	if (y%2==0){ X1 = x-1; X2 = x;}
	else { X1 = x; X2 = x+1;}
	
	if ((x!=0 || X1==x) && (x!=(size/2)-1 || X2==x)){
		if (Board[x][y]->isKing){
			return (!isExistPawn(X1,y+1) || !isExistPawn(X2,y+1) || !isExistPawn(X1,y-1) || !isExistPawn(X2,y-1));
		}else if (Board[x][y]->side==WHITE){
			return (!isExistPawn(X1,y+1) || !isExistPawn(X2,y+1));
		}else {
			return (!isExistPawn(X1,y-1) || !isExistPawn(X2,y-1));		
		}
	} else if (x==0 && X1!=x){
		if (Board[x][y]->isKing){
			return (!isExistPawn(X2,y-1) || !isExistPawn(X2,y+1));			
		} else if (Board[x][y]->side==WHITE){
			return (!isExistPawn(X2,y+1));			
		} else {
			return (!isExistPawn(X2,y-1));			
		}
	}  else {
		if (Board[x][y]->isKing){
			return (!isExistPawn(X1,y-1) || !isExistPawn(X1,y+1));			
		} else if (Board[x][y]->side==WHITE){
			return (!isExistPawn(X1,y+1));			
		} else {
			return (!isExistPawn(X1,y-1));			
		}
	}
}

bool CheckerBoard::checkMove(bool turn)
{
	int i,j;
	bool temp = false;
	for(i=0;i<size/2 && !temp;i++){
		for(j=0;j<size && !temp;j++){
			if(turn==WHITE && isExistWhitePawn(i,j)){
				temp = temp || isMoveable(i,j);
			}else if (turn==BLACK && isExistBlackPawn(i,j)){
				temp = temp || isMoveable(i,j);
			}
		}	
	}
	return temp;
}

bool CheckerBoard::isJumpAvailable(int x1, int y1, int x2, int y2, bool side, bool isKing)
{
	if (isExistPawn(x2,y2))
	{
		return false;
	}
	
	if (y1%2==0)
	{
		if (x2==x1+1 && y2==y1+2 && isExistPawn(x1,y1+1) && Board[x1][y1+1]->side != side && (isKing || side==WHITE)) 
		{
			return true;
		}
		else if(x2==x1-1 && y2==y1+2 && isExistPawn(x1-1,y1+1) && Board[x1-1][y1+1]->side != side && (isKing || side==WHITE))
		{
			return true;
		}
		else if(x2==x1+1 && y2==y1-2 && isExistPawn(x1,y1-1) && Board[x1][y1-1]->side != side && (isKing || side==BLACK))
		{
			return true;
		}
		else if(x2==x1-1 && y2==y1-2 && isExistPawn(x1-1,y1-1) && Board[x1-1][y1-1]->side != side && (isKing || side==BLACK))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		if (x2==x1+1 && y2==y1+2 && isExistPawn(x1+1,y1+1) && Board[x1+1][y1+1]->side != side && (isKing || side==WHITE)) 
		{
			return true;
		}
		else if(x2==x1-1 && y2==y1+2 && isExistPawn(x1,y1+1) && Board[x1][y1+1]->side != side && (isKing || side==WHITE))
		{
			return true;
		}
		else if(x2==x1+1 && y2==y1-2 && isExistPawn(x1+1,y1-1) && Board[x1+1][y1-1]->side != side && (isKing || side==BLACK))
		{
			return true;
		}
		else if(x2==x1-1 && y2==y1-2 && isExistPawn(x1,y1-1) && Board[x1][y1-1]->side != side && (isKing || side==BLACK))
		{
			return true;
		}
		else 
		{
			return false;
		}
	}
}

bool CheckerBoard::isJumpAvailableLeftTop(int x1, int y1, bool side, bool isKing)
{	
	if (x1<=0 || y1 < 2){ 
		return false; 
	}else{
		return (isJumpAvailable(x1,y1,x1-1,y1-2,side,isKing));
	}
}

bool CheckerBoard::isJumpAvailableRightTop(int x1, int y1, bool side, bool isKing)
{
	if (x1>=(size/2)-1 || y1 < 2){ 
		return false; 
	}else{
		return (isJumpAvailable(x1,y1,x1+1,y1-2,side,isKing));
	}
} 	

bool CheckerBoard::isJumpAvailableLeftBottom(int x1, int y1, bool side, bool isKing)
{
	if (x1<=0 || y1 > size-3){ 
		return false; 
	}else{
		return (isJumpAvailable(x1,y1,x1-1,y1+2,side,isKing));
	}	
} 

bool CheckerBoard::isJumpAvailableRightBottom(int x1, int y1, bool side, bool isKing)
{
	if (x1>=(size/2)-1 || y1 > size-3){ 
		return false; 
	}else{
		return (isJumpAvailable(x1,y1,x1+1,y1+2,side,isKing));
	}	
} 

int* CheckerBoard::searchMaximum(int x, int y, bool side, bool isKing, int* Move, int count){
	int* tempLT = (int*) malloc (21*sizeof (int));
	int* tempRT = (int*) malloc (21*sizeof (int));
	int* tempLB = (int*) malloc (21*sizeof (int));
	int* tempRB = (int*) malloc (21*sizeof (int));
	bool tempKing = false;
	int i;
	
	if (x<0 || x>(size/2)-1 || y<0 || y>size-1){
		return Move;
	}
	
	for (i=0;i<=count;i++){
		tempLT[i] = Move[i];
		tempRT[i] = Move[i];
		tempLB[i] = Move[i];
		tempRB[i] = Move[i];
	}
	if ((!isJumpAvailableLeftTop(x,y,side,isKing) &&
			!isJumpAvailableRightTop(x,y,side,isKing) &&
			!isJumpAvailableLeftBottom(x,y,side,isKing) &&
			!isJumpAvailableRightBottom(x,y,side,isKing)) ||
		Move[count-1]==END) {
		return Move;											// basis
	}else {	
		if (isKing){
			if (isJumpAvailableLeftTop(x,y,side,isKing) && Move[count-1]!=RB){
				tempLT[count]=LT;
			} else {
				tempLT[count]=END;
			}
			
			
			if (isJumpAvailableRightTop(x,y,side,isKing) && Move[count-1]!=LB){
				tempRT[count]=RT;
			} else {
				tempRT[count]=END;
			}
			
			if (isJumpAvailableLeftBottom(x,y,side,isKing) && Move[count-1]!=RT){
				tempLB[count]=LB;
			} else {
				tempLB[count]=END;
			}
			
			if (isJumpAvailableRightBottom(x,y,side,isKing) && Move[count-1]!=LT){
				tempRB[count]=RB;
			} else {
				tempRB[count]=END;
			}
			
			return (maxList(
						(maxList(searchMaximum(x-1,y-2,side,isKing,tempLT,count+1),searchMaximum(x+1,y-2,side,isKing,tempRT,count+1))),
						(maxList(searchMaximum(x-1,y+2,side,isKing,tempLB,count+1),searchMaximum(x+1,y+2,side,isKing,tempRB,count+1)))
						));
		}else if (side==BLACK){
			if (isJumpAvailableLeftTop(x,y,side,isKing)){
				tempLT[count]=LT;
				if (y==1){ tempKing = true; }
			} else {
				tempLT[count]=END;
			}
			
			if (isJumpAvailableRightTop(x,y,side,isKing)){
				tempRT[count]=RT;
				if (y==1){ tempKing = true; }
			} else {
				tempRT[count]=END;
			}
			
			return (maxList(searchMaximum(x-1,y-2,side,tempKing,tempLT,count+1),searchMaximum(x+1,y-2,side,tempKing,tempRT,count+1)));
		}else {
			if (isJumpAvailableLeftBottom(x,y,side,isKing)){
				tempLB[count]=LB;
				if (y==size-2){ tempKing = true; }
			} else {
				tempLB[count]=END;
			}
			
			if (isJumpAvailableRightBottom(x,y,side,isKing)){
				tempRB[count]=RB;
				if (y==size-2){ tempKing = true; }
			} else {
				tempRB[count]=END;
			}
			
			return (maxList(searchMaximum(x-1,y+2,side,isKing,tempLB,count+1),searchMaximum(x+1,y+2,side,isKing,tempRB,count+1)));
		}
	}	
}

int* CheckerBoard::maxList(int* list1, int* list2){
	if (listSize(list1) > listSize(list2)){
		return list1;
	}else {
		return list2;
	}
}

int CheckerBoard::listSize(int* list){ //List[20]
	int i = 0;
	if (list[1]==START){return 0;}
	
	while (list[i]!=END){
		i++;
	}
	
	return i;
}
	
void CheckerBoard::checkJump(int jx, int jy)
{
	int i, it;
	int x, y;
	ListOfPoint tempList;
	
	int* temp = (int*) malloc (21 * sizeof (int));
	for (i=0;i<=20;i++){
		temp[i]=START;
	}
	
	i = 0;
	if (jx == 10 && jy == 10){
		tempList = getAddress(LoEat,i);
		while (tempList != NULL){
			x = getX(LoEat,i);
			y = getY(LoEat,i);
			if (listSize(temp) < listSize(searchMaximum(x,y,Board[x][y]->side,Board[x][y]->isKing,temp,1))){
				temp = searchMaximum(x,y,Board[x][y]->side,Board[x][y]->isKing,temp,1);
				it = i;
			}
			i++;
			tempList = getAddress(LoEat,i);
		}
		x = getX(LoEat,it);
		y = getY(LoEat,it);
	} else {
		x = jx;
		y = jy;
		temp = searchMaximum(jx,jy,Board[jx][jy]->side,Board[jx][jy]->isKing,temp,1);
	}
	add(&LoJump,x,y);
	i = 1;
	while (temp[i]!=0 && i<=21){	
		if (temp[i]==1){
			add(&LoJump,x-1,y-2);
			x = x - 1;
			y = y - 2;
		}else if (temp[i]==2){
			add(&LoJump,x+1,y-2);
			x = x + 1;
			y = y - 2;
		}else if (temp[i]==3){
			add(&LoJump,x-1,y+2);
			x = x - 1;
			y = y + 2;		
		}else if (temp[i]==4){
			add(&LoJump,x+1,y+2);
			x = x + 1;
			y = y + 2;
		} 
		i++;
	}
}

void CheckerBoard::move(int x1, int y1, int x2, int y2)
{
	if (isMoveAllowed(x1,y1,x2,y2) && (turn==Board[x1][y1]->side))
	{
		Pawn temp;
		Board[x2][y2] = Board[x1][y1];
		Board[x1][y1] = NULL;

		if ((y2==size-1 && (Board[x2])[y2]->side==WHITE) || (y2==0 && Board[x2][y2]->side==BLACK))
		{
			Board[x2][y2]->isKing = true;
		}
	
		if (!isEmpty(LoEat))
		{
			if (!isEatAllowed(x2,y2))
			{
				jumpAIx = 10;
				jumpAIy = 10;
				if (turn==WHITE){turn=BLACK;}
				else {turn = WHITE;}
			} 
			else 
			{
				jumpAIx = x2;
				jumpAIy = y2;
			}
		}
		else
		{
			if (turn==WHITE){turn=BLACK;}
			else {turn = WHITE;}	
		}
	}
}

void CheckerBoard::countNumberOfPawn(){
	int nop1 = 0,nop2 = 0;
	int i,j;
	for (i=0;i<=(size/2)-1;i++){
		for (j=0;j<=size-1;j++){
			if (isExistWhitePawn(i,j)){nop1++;}
			if (isExistBlackPawn(i,j)){nop2++;}
		}
	}
	numberOfPawn1 = nop1;
	numberOfPawn2 = nop2;
}

void CheckerBoard::printBoard()
{		
	int i,j;
	cout << "___________________________________________"<< endl;
	for (j=0;j<size;j++)
	{
	cout << j << "| ";
		for (i=0;i<size;i++)
		{
			if (isExistPawn(i/2,j) )
			{
				if (j%2 == 0)
				{
					if (Board[i/2][j]->side==WHITE && i%2==0)
					{
						if(Board[i/2][j]->isKing)
						{
							cout << "^ | ";
						}
						else 
						{
							cout << "O | ";
						}
					}
					else if (Board[i/2][j]->side==BLACK && i%2==0)
					{
						if(Board[i/2][j]->isKing)
						{
							cout << "V | ";
						}
						else 
						{
							cout << "X | "; 
						}
					}
					else 
					{
						cout << "  | ";					
					}
				}
				else 
				{
					if (Board[i/2][j]->side==WHITE && i%2==1)
					{
						if(Board[i/2][j]->isKing)
						{
							cout << "^ | ";
						}
						else 
						{
							cout << "O | ";
						}
					}
					else if (Board[i/2][j]->side==BLACK && i%2==1)
					{
						if(Board[i/2][j]->isKing)
						{
							cout << "V | ";
						}
						else 
						{
							cout << "X | ";
						}
					}	
					else
					{
						cout << "  | ";				
					}
				}
			}
			else 
			{
				cout << "  | ";
			}
		}
	cout << endl;
	}
	cout << "-------------------------------------------\n";
	cout << "   0   0   1   1   2   2   3   3\n";
}


